//
//  HWQQGameTypeProtocol.swift
//  HWanGame
//
//  Created by 王昌健 on 2023/6/5.
//  Copyright © 2023 94hwan. All rights reserved.
//

import UIKit

class HWQQGameTypeProtocol: NSObject {
    var models:[HWQQGameListModel]?
    
    var gameButtonClick:((_ mod:HWQQGameListModel)->())?
}

extension HWQQGameTypeProtocol: UITableViewDelegate,UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if indexPath.section == 1 {
            gameButtonClick?(models?[indexPath.row + 3] ?? HWQQGameListModel())
        }
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            if (models?.count ?? 0) > 0 {
                return 1
            }
        } else {
            if (models?.count ?? 0) > 3 {
                return (models?.count ?? 0) - 3
            }
        }
        
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let topCell = HWQQGameTypeTopCell.cellWithTableView(tableView)
        let normalCell = HWQQGameTypeNormalCell.cellWithTableView(tableView)
        normalCell.model = models?[indexPath.row + 3]
        if indexPath.section == 0 {
            topCell.models = models
            topCell.gameButtonClick = {
                self.gameButtonClick?($0)
            }
            return topCell
        } else {
            normalCell.indexPath = indexPath
            normalCell.model = models?[indexPath.row + 3]
            return normalCell
        }
    }
    
    
}
